﻿@{
    ViewBag.Title = "采购单列表";
    Layout = "~/Views/Shared/_LayoutList.cshtml"; 
}
@(       
 Html.DWZGridFor<Resto.CostControl.Core.MaterialPurchase>()
    .ID("grilList")
    .Title("采购单列表")
    .Action(@Url.Action("Index"))
    .Columns(col =>
    {
        col.Bind(e => e.Id).IsKey();
        //col.Bind(e => e.Code).Width(80).AsQuery().Align(FlexiGridAlign.Left);
        col.Bind(e => e.OrderDate).Width(70).DateFormat("yyyy-MM-dd");
        col.Bind(e => e.SupplierId).EnumKey("Supplier").Width(140).Align(FlexiGridAlign.Left);
        col.Bind(e => e.TotalPrice).Width(60).Align(FlexiGridAlign.Right);
        col.Bind(e => e.ItemDesc).Width("auto").Align(FlexiGridAlign.Left);
        col.Bind(e => e.OrderState).Width(40).EnumKey("PurchaseState");
        col.Bind(e => e.UpdateUser).Width(60);
        col.Bind(e => e.UpdateDate).Width(70).DateFormat("yyyy-MM-dd");
        col.Bind(e => e.Id, "操作", 180).Sortable(false)
            .Template(Url.GridLink("accept", "发货", "SingleOrderDelivery('${Id}')")
            + Url.EditLinkTwo(Url.Action("Edit"), "编辑采购单")
            + Url.DeleteLink("Delete", "${OrderDate}"));
    })
    .Buttons(btn =>
    {
        btn.Bind("Edit", "新建采购订单", FlexiGridButtonType.Add).Action(@Url.Action("Edit")).OnPress("AddNewTwo");
    })
)
<script type="text/javascript">
    function OrderDelivery() {
        if (confirm("你确定要发货?")) {
            var selectRows = $("#grilList").getSelectedRows();
            if (selectRows.length == 0) {
                alert("请先选择一条/多条记录");
                return;
            }
            showLoadingMsg("正在发货...", { left: 300, top: 2 })
            $.post('@Url.Action("Delivery")', selectRows,
                     function (data) {
                         if (data.IsSuccess) {
                             showLoadingMsg("发货成功", { left: 300, top: 2 }, true, 3000);
                             flushGrid();
                         }
                         else {
                             hideLoadingMsg();
                             showErrorTip(data.Msg, { left: 300, top: 2 }, true, 5000);
                         }
                     },
                "json"
                );
        }
    }

    function SingleOrderDelivery(Id) {
        if (confirm("你确定要发货?")) {
            showLoadingMsg("正在发货...", { left: 300, top: 2 })
            $.post('@Url.Action("SingleDelivery")', { id: Id },
                     function (data) {
                         if (data.IsSuccess) {
                             showLoadingMsg("发货成功", { left: 300, top: 2 }, true, 3000);
                             $("#grilList").flexReload();
                         }
                         else {
                             hideLoadingMsg();
                             showErrorTip(data.Msg, { left: 300, top: 2 }, true, 5000);
                         }
                     },
                "json"
                );
        }
    }

</script>
